import Vue from 'vue'
import Router from 'vue-router'
import LoginPage from '../views/LoginPage.vue'
import HomePage from '../views/HomePage.vue'
import PetList from "../components/PetList.vue"
import PetDetail  from '../components/PetDetail.vue'
Vue.use(Router)
const router = new Router({
  routes: [
    {
      path: '/LoginPage',
      name: 'LoginPage',
      component: LoginPage
    },
    {
      path: '/',
      redirect: '/LoginPage',  // 默认重定向到 LoginPage
    },
    {
      path: '/HomePage',
      name: 'HomePage',
      component: HomePage,
      meta: { requiresAuth: true }
    },
      {
      path: '/',
      name: 'PetList',
      component: PetList,
    },
    {
      path: '/pet/:id',
      name: 'PetDetail',
      component: PetDetail, // 指定 PetDetail 作为该路径的组件
    },
  ]
})

// 路由守卫
// router.beforeEach((to, from, next) => {
//   const isAuthenticated = router.app.$store.state.user;
//   if (to.meta.requiresAuth && !isAuthenticated) {
//     next('/LoginPage'); // 未认证用户重定向
//   } else if (to.path === '/LoginPage' && isAuthenticated) {
//     next('/'); // 认证用户跳转到主页
//   } else {
//     next(); // 继续路由
//   }
// });

export default router